package cn.itchao.example.member.api.service;

import cn.itchao.example.member.domain.Member;
import cn.itchao.example.member.service.MemberService;
import cn.itchao.exmaple.base.ApiResponse;
import cn.itchao.example.member.api.MemberServiceApi;
import cn.itchao.example.member.dto.MemberDto;
import org.apache.dubbo.config.annotation.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@Service
@RestController
@RefreshScope
public class MemberServiceApiImpl implements MemberServiceApi {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Value("${user.name}")
    String userName;

    @Autowired
    private MemberService memberService;

    @GetMapping("/member/{id}")
    @Override
    public ApiResponse<MemberDto> findMemberById(@PathVariable("id") Long id) {
        logger.info("userName:{}",userName);
        Member member = memberService.queryMemberById(id);
        MemberDto memberDto = new MemberDto();
        BeanUtils.copyProperties(member,memberDto);
        return ApiResponse.ofSuccess(memberDto);
    }
}
